<!-- <!doctype html> -->
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>华富</title>

    <link rel="stylesheet" type="text/css" href="css/api.css" />
    <link rel="stylesheet" type="text/css" href="css/common.css" />
    <link rel="stylesheet" type="text/css" href="css/aui.css" />
    <link rel="stylesheet" type="text/css" href="css/aui-pull-refresh.css" />
    <link rel="stylesheet" type="text/css" href="css/style.css" />
    <style>
        img {
            width: 22px;
            margin: auto;
        }
    </style>
</head>

<body>
    <div id="app">
        <footer class="aui-bar aui-bar-tab" id="footer">
            <div class="aui-bar-tab-item aui-active " tapmode>
                <img src="image/footer/index_on.png" alt="">
                <div class="aui-bar-tab-label check_active">首页</div>
            </div>
            <div class="aui-bar-tab-item" tapmode>
                <img src="image/footer/class_off.png" alt="">
                <div class="aui-bar-tab-label">分类</div>
            </div>
            <div class="aui-bar-tab-item" tapmode>
                <div class="aui-dot aui-hide"></div>
                <img src="image/footer/share_off.png" alt="">
                <div class="aui-bar-tab-label">赚赚</div>
            </div>
            <div class="aui-bar-tab-item" tapmode>
                <span class="aui-badge" id="cartBadge" style="display: none"></span>
                <img src="image/footer/cart_off.png" alt="">
                <div class="aui-bar-tab-label">购物车</div>
            </div>
            <div class="aui-bar-tab-item" tapmode>
                <img src="image/footer/user_off.png" alt="" style="width:1.9rem;">
                <div class="aui-bar-tab-label">我的</div>
            </div>
        </footer>
    </div>
</body>
<script type="text/javascript" src="script/api.js"></script>
<script type="text/javascript" src="script/zepto.js"></script>
<script type="text/javascript" src="script/vue.min.js"></script>
<script type="text/javascript" src="script/utils.js"></script>
<script type="text/javascript" src="script/common.js"></script>
<script type="text/javascript" src="script/aui-tab.js"></script>
<script type="text/javascript" src="script/aui-scroll.js"></script>
<script type="text/javascript" src="script/aui-pull-refresh.js"></script>

<script type="text/javascript">
    var footer = $api.byId('footer');
    var footerPos = $api.offset(footer);

    apiready = function() {


        api.addEventListener({
            name: 'appintent'
        }, function(ret, err){
            if( ret ){
                //  alert( JSON.stringify( ret ) );
                var get_share_goodsId = ret.appParam.goodsId;
                if(get_share_goodsId != '' && get_share_goodsId != null && get_share_goodsId != undefined){
                  api.openWin({
                      name: 'classDetailHeader',
                      url: 'html/class/class_detail_header.html',
                      pageParam: {
                          goodsId:get_share_goodsId
                      }
                  });
                }
                // alert(get_share_goodsId)
            }else{
                 alert( JSON.stringify( err ) );
            }
        });

        //setRefresh()
        openframeinstance('index/index.html', 6);
        //同步返回结果：
        var installed = api.appInstalled({
            sync: true,
            appBundle: 'huafuapp'
        });
        if (installed) {
            //应用已安装
        } else {
            //应用未安装
        }
        api.addEventListener({   //从其他按钮点击跳转到frame
            name:"change_tab"},

            function(ret,err){
                var index = ret.value.index  //需要改变的index
                var html =  ret.value.name  //路径
                var d_index =  ret.value.d_index  //原index
                var frm_name = ['index', 'class', 'share', 'cart', 'user'];
                $('#footer .aui-bar-tab-item').eq(index).find('img').prop('src', 'image/footer/' + frm_name[index] + '_on.png')
                tab.setActive(index+1)
                $('#footer .aui-bar-tab-item').eq(d_index).find('img').prop('src', 'image/footer/' + frm_name[d_index] + '_off.png')
                openframeinstance(html, 6)
        })
        $api.setStorage('footerPos_h', footerPos.h);
        openframeinstance('index/index.html', 6)
    };

    //刷新
    function setRefresh() {
        var pullRefresh = new auiPullToRefresh({
            container: document.querySelector('.aui-refresh-content'),
            triggerDistance: 100
        }, function(ret) {

            if (ret.status == "success") {
                setTimeout(function() {
                    pullRefresh.cancelLoading(); //刷新成功后调用此方法隐藏
                }, 1500)
            }
        })
    }

    var tab = new auiTab({
        element: document.getElementById("footer"),
        index: 1,
        repeatClick: false
    }, function(ret) {
        switch (ret.index) {
            case 1:
                openframeinstance('index/index.html', 6)
                break;
            case 2:
                openframeinstance('class/index.html', 6)
                break;
            case 3:
                openframeinstance('share/index.html', 6)
                break;
            case 4:
                openframeinstance('cart/index.html', 6)
                break;
            case 5:
                openframeinstance('user/index.html', 6)
                break;
            default:
                console.log('home')
                break;
        }

        var frm_index = ret.index - 1;
        var frm_name = ['index', 'class', 'share', 'cart', 'user'];

        for (var i = 0; i < 5; i++) {
            if (i == frm_index) {
                $('#footer .aui-bar-tab-item').eq(i).find('img').prop('src', 'image/footer/' + frm_name[i] + '_on.png')
            } else {
                $('#footer .aui-bar-tab-item').eq(i).find('img').prop('src', 'image/footer/' + frm_name[i] + '_off.png')
            }
        }

    });

    // 隐藏所有的一级frame
    function hideAllFrame() {
        api.setFrameAttr({
            name: 'index/index.html',
            hidden: true
        });
        api.setFrameAttr({
            name: 'class/index.html',
            hidden: true
        });
        api.setFrameAttr({
            name: 'share/index.html',
            hidden: true
        });
        api.setFrameAttr({
            name: 'cart/index.html',
            hidden: true
        });
        api.setFrameAttr({
            name: 'user/index.html',
            hidden: true
        });
    }

    // 展示指定的frame
    function showframe(type) {
        api.setFrameAttr({
            name: type,
            hidden: false
        });
    }

    // 打开frame
    function openframeinstance(frame, marginTop) {
        hideAllFrame()
        api.openFrame({
            reload: true,
            name: frame,
            url: './html/' + frame + '',
            rect: {
                x: 0,
                y: 25,
                w: 'auto',
                h: api.frameHeight - marginTop - (footerPos.h)-10
            },
            pageParam: {
                name: '1'
            },
            // bounces: isBounce,
            bounces: false,
            vScrollBarEnabled: false,
            hScrollBarEnabled: false,
            delay: 200
        });
    }


</script>


</html>
